package com.zezer.site.dao;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class BaseDao {

	protected static Connection getConnection() throws SQLException {
		String url = getUrl();
		String username = getUsername();
		String password = getPassword();

		Connection conn = DriverManager.getConnection(url, username, password);
		return conn;
	}
	
	protected static void executeCallableStatement(CallableStatement cs) throws SQLException {
		cs.execute();
	}
	
	protected static void executeQuery(CallableStatement cs) throws SQLException {
		cs.executeQuery();
	}
	
	protected static int executeUpdate(CallableStatement cs) throws SQLException {
		return cs.executeUpdate();
	}

	protected static String getUrl() {
		return "jdbc:mysql://localhost:3306/zezer";
	}

	protected static String getUsername() {
		return "zezer_rw";
	}

	protected static String getPassword() {
		return "testuser";
	}

	protected static void clean(Connection conn, CallableStatement cs) {
		if (cs != null) {
			try {
				cs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if (conn != null) {
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		conn = null;
		cs = null;
	}
}
